package com.hongzhimei.yukicomic.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.hongzhimei.yukicomic.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by wuwei on 2016/12/21.
 */

public class WelfareTimeAdapter extends RecyclerView.Adapter<WelfareTimeAdapter.ViewHolder> {
    Context context;
    List<String> list;
    private onItemClickLitener monItemClickLitener;

    public WelfareTimeAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.welfaretime_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    public void setOnItemClickLitener(onItemClickLitener monItemClickLitener) {
        this.monItemClickLitener = monItemClickLitener;
    }


    public interface onItemClickLitener {
        void onItemClick(View view, int postion);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Glide.with(context).load(list.get(position)).into(holder.welfaretimeImg);
        if (monItemClickLitener != null) {
            holder.welfaretimeItemLinear.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    monItemClickLitener.onItemClick(holder.itemView,holder.getLayoutPosition());
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.welfaretime_img)
        ImageView welfaretimeImg;
        @Bind(R.id.welfaretime_item_linear)
        LinearLayout welfaretimeItemLinear;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
